const fs = require('fs')
const path = require('path')

const getMillis = time => {
  const reg = /(\d{2}):(\d{2})\.(\d{2})/
  const [, m, s, ms] = reg.exec(time)
  return m * 60 * 1000 + s * 1000 + ms * 10
  // const arr = time.split(':')
  // return arr[0] * 60 * 1000 + arr[1] * 1000
}

fs.readFile(path.join(__dirname, './天外来物-薛之谦.txt'), 'utf8', (err, data) => {
  if (err) return console.log('读取文件失败')
  const timeReg = /\[(\d{2}:\d{2}\.\d{2})\](.*)\r\n/g
  let result
  while (true) {
    result = timeReg.exec(data)
    if (!result) {
      break
    }
    const [, time, text] = result
    setTimeout(() => {
      console.log(text)
    }, getMillis(time))
  }
})